package com.zhuoshi.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.zhuoshi.entity.Room;
import com.zhuoshi.entity.RoomCustom;
import com.zhuoshi.mapper.RoomMapper;
import com.zhuoshi.service.RoomService;
import com.zhuoshi.util.CreateExcel;
import com.zhuoshi.util.ImportExecl;

@Service("roomService")
@Transactional
public class RoomServiceImpl implements RoomService{

	@Autowired
	private RoomMapper roomMapper;
	@Autowired
	private CreateExcel createExcel;
	@Autowired
	private ImportExecl importExecl;
	
	//查询房间
	public List<RoomCustom> selectAllRoomLiu(Float minArea,Float maxArea) {
		return roomMapper.selectAllRoomLiu(minArea,maxArea);
	}
	
	//添加房间
	public Integer addRoomLiu(Room room) {
		return roomMapper.insertSelective(room);
	}
	
	//删除房间（主键）
	public Integer deleteRoomLiu(Integer id) {
		return roomMapper.deleteByPrimaryKey(id);
	}
	
	//根据id查询房间包装类
	public RoomCustom selectRoomCustomById(Integer id) {
		return roomMapper.selectRoomCustomById(id);
	}
	
	//修改房间
	public Integer updateRoomConfirmLiu(Room room,Integer id) {
		return roomMapper.updateByPrimaryKeySelective(room);
	}

	public List<RoomCustom> selectAllRoomYao() throws Exception {
		List<RoomCustom> roomCustoms=roomMapper.selectAllRoomYao();
		for(int i=0;i<roomCustoms.size();i++){
			if(roomCustoms.get(i).getState().equals("已销售")){
				roomCustoms.remove(i);
			}
		}
		return roomCustoms;
	}

	public List<RoomCustom> selectRoomByIdsYao(Integer[] ids) throws Exception {
		
		List<RoomCustom> roomCustoms=new ArrayList<RoomCustom>();
		for(int i=0;i<ids.length;i++){
			if(i==ids.length-1&&ids[i]==null){
				break;
			}
			roomCustoms.add(roomMapper.selectRoomByIdsYao(ids[i]));
		}
		return roomCustoms;
	}
	
//	根据批量Id查房间(导出Execl)
public List<RoomCustom> exportExeclYao(Integer[] ids) throws Exception {
	List<RoomCustom> roomCustoms=new ArrayList<RoomCustom>();
	for(int i=0;i<ids.length;i++){
		if(i==ids.length-1&&ids[i]==null){
			break;
		}
		roomCustoms.add(roomMapper.selectRoomByIdsYao(ids[i]));
	}
	createExcel.createExcel(roomCustoms);
	return roomCustoms;
}
//读取Execl返回房间
public List<RoomCustom> importExeclYao() throws Exception {
	List<RoomCustom> roomCustoms = importExecl.importExecl();
	return roomCustoms;
}
	public List<RoomCustom> selectRoomByIdsYao(int roomid) {
		
		return null;
	}

	public List<RoomCustom> selectRoomByIdsLu(Integer unitId) {
		return roomMapper.selectRoomByIdsLu(unitId);
	}

}
